﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using University.Workshop.DataAccess;

namespace University.Workshop.ServerApp
{
    /// <summary>
    /// Interaction logic for Unban.xaml
    /// </summary>
    public partial class Unban : Window
    {
        DatabaseQuery data = new DatabaseQuery();
        public Unban()
        {
            InitializeComponent();
            foreach (User user in data.GetAllBannedUsers)
            {
                listBox1.Items.Add(user.Name);
            }
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {

        }

        private void listBox1_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (listBox1.SelectedIndex > -1)
                textBox2.Text = listBox1.SelectedItem.ToString();
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            if (data.BanUser(textBox2.Text, "False", DateTime.Now))
            {
                MessageBox.Show("user Unbanned");
                listBox1.Items.Remove(textBox2.Text);
                listBox1.SelectedIndex = -1;
                textBox2.Text = "";
                       
            }
        }

        private void button2_Click(object sender, RoutedEventArgs e)
        {
            listBox1.Items.Clear();
            foreach (User user in data.GetAllBannedUsers)
            {
                listBox1.Items.Add(user.Name);
            }
        }
    }
}
